package com.ruoyi.project.module.cloudCpe.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.cloudCpe.domain.CloudCpe;
import com.ruoyi.project.module.cloudCpe.service.ICloudCpeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * CPE管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-07-24
 */
@Controller
@RequestMapping("/module/cloudCpe")
public class CloudCpeController extends BaseController
{
    private String prefix = "module/cloudCpe";
	
	@Autowired
	private ICloudCpeService cloudCpeService;
	
	@RequiresPermissions("module:cloudCpe:view")
	@GetMapping()
	public String cloudCpe()
	{
	    return prefix + "/cloudCpe";
	}
	
	
	@GetMapping("/cloudCpeDetail")
	public String cloudCpeDetail()
	{
	    return prefix + "/cloudCpeDetail";
	}
	
	
	/**
	 * 查询CPE管理列表
	 */
	@RequiresPermissions("module:cloudCpe:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CloudCpe cloudCpe)
	{
		startPage();
        List<CloudCpe> list = cloudCpeService.selectCloudCpeList(cloudCpe);
		return getDataTable(list);
	}
	
	
	
	/**
	 * 新增CPE管理
	 */
	@RequiresPermissions("module:cloudCpe:add")
	@Log(title = "CPE管理", action = BusinessType.INSERT)
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改CPE管理
	 */
	@RequiresPermissions("module:cloudCpe:edit")
	@Log(title = "CPE管理", action = BusinessType.UPDATE)
	@GetMapping("/edit/{cpeId}")
	public String edit(@PathVariable("cpeId") Integer cpeId, Model model)
	{
		CloudCpe cloudCpe = cloudCpeService.selectCloudCpeById(cpeId);
		model.addAttribute("cloudCpe", cloudCpe);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改CPE管理
	 */
	@Log(title = "CPE管理", action = BusinessType.UPDATE)
	@GetMapping("/editQos/{cpeId}")
	public String editQos(@PathVariable("cpeId") Integer cpeId, Model model)
	{
		CloudCpe cloudCpe = cloudCpeService.selectCloudCpeById(cpeId);
		model.addAttribute("cloudCpe", cloudCpe);
	    return prefix + "/editQos";
	}
	
	
	
	/**
	 * 修改CPE管理
	 */
	@Log(title = "CPE管理", action = BusinessType.UPDATE)
	@GetMapping("/editWifi/{cpeId}")
	public String editWifi(@PathVariable("cpeId") Integer cpeId, Model model)
	{
		CloudCpe cloudCpe = cloudCpeService.selectCloudCpeById(cpeId);
		model.addAttribute("cloudCpe", cloudCpe);
	    return prefix + "/editWifi";
	}
	
	/**
	 * 保存CPE管理
	 */
	@RequiresPermissions("module:cloudCpe:save")
	@Log(title = "CPE管理", action = BusinessType.SAVE)
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(CloudCpe cloudCpe)
	{
		if (cloudCpeService.saveCloudCpe(cloudCpe) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除CPE管理
	 */
	@RequiresPermissions("module:cloudCpe:remove")
	@Log(title = "CPE管理", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = cloudCpeService.deleteCloudCpeByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
